var vm = new Vue({
    el: '#main',
    data: {
        versionDatas:[],
        pagination: [],
        versionObj:{
            systemNo:'',
            systemName:'',
            systemChargePop:'',
            systemPhone:'',
            systemPhoneType:'',
            systemUrl:'',
            systemDateUrl:'',
            serverConStr:'',
            password:'',
            fileUrl:'',
            fileName:'',
            autoFlag:'1',
        },
        editObj:{
            versionNo:'',
            versionUpdateTime:'',
            versionUrl:'',
            versionCopyUrl:{},
            fileName:'',
            sysversionId:'',
        },
        nowPage:1,
        rowNum:10,
        allPages:0,
        Obj:{},
        flag:true,
        tips:'',
        jumpPage:'',
        listLength:'',
    },
    created: function () {
        this.Obj = sessionStorage.getItem('obj')
        this.versionObj = JSON.parse(this.Obj);
        this.getData();
    },
    methods:{
        //保存
        check_c(){
            let obj = {
                systemNo:this.versionObj.systemNo,
                systemName:this.versionObj.systemName,
                systemChargePop:this.versionObj.systemChargePop,
                systemPhone:this.versionObj.systemPhone,
                systemPhoneType:this.versionObj.systemPhoneType,
                systemUrl:this.versionObj.systemUrl,
                systemDateUrl:this.versionObj.systemDateUrl,
                serverConStr:this.versionObj.serverConStr,
                password:this.versionObj.password,
                fileUrl:this.versionObj.fileUrl,
                fileName:this.versionObj.fileName,
                autoFlag:this.versionObj.autoFlag,
                id:this.versionObj.id,
            }
            axios({
                method: "post",
                url: App.envUrl.backtrackUrl+"sysMaintain/updateSysMaintain",
                data: obj,
            })
            .then((data) => {
                if(data.data.code === '200'){
                    window.location.href = 'systemEnqu.html'
                }
            })
            .catch((err) => {});
        },
          //测试一下
          resetBtn(){
            let promes = {
                serverConStr:this.versionObj.serverConStr,
                password:this.versionObj.password,
            };
            axios({
                method: "post",
                url: App.envUrl.backtrackUrl+"sysMaintain/testConnect",
                data: promes,
            })
            .then((data) => {
                if(data.data.code === '200'){
                    $('#my-alert1').modal({
                        relatedTarget: this,
                    });
                    this.tips = '服务器可连接';
                }
            })
            .catch((err) => {});
        },
        radioChangez(val){
            this.versionObj.autoFlag = '1';
         },
         radioChanges(val){
             this.versionObj.autoFlag = '0'
         },
        //返回
        back(){
            window.location.href =
            "systemEnqu.html";
        },
        //返回到维护页
        backMaintenance(){
            window.location.href =
                "systemMaintenance.html";
        },
        //列表
        getData(){
            let obj = {
                id:this.versionObj.id,
                nowPage: this.nowPage,
            }
            axios({
                method: "post",
                url: App.envUrl.backtrackUrl+"version/querySysMaintain",
                data: obj,
            })
            .then((data) => {
                console.log(data,'版本');
                if(data.data.code === '200'){
                    this.versionDatas = data.data.pageCount.datas;
                    this.nowPage = data.data.pageCount.nowPage;
                    this.allPages = data.data.pageCount.allPages;
                    this.pagination = getPagination(this.nowPage,this.allPages);
                    this.listLength = data.data.pageCount.allCount;
                }else{
                    parent.showAlert(data.data.msg);
                }
            })
            .catch((err) => {});
        },
        //新增
        addBtn(){
            this.flag = true;
            $('#my-alert').modal({
                relatedTarget: this,
            });
            this.editObj.versionNo = '';
            this.editObj.versionUpdateTime = this.getTimer();
            this.editObj.versionUrl = '';
            this.editObj.fileName = '';
        },
        //查看页面
        lookPage(sysversionId){
        //    window.location.href = 'sysPages.html?sysversionId=' + sysversionId;  // 原跳转页面
           window.location.href = 'sysList.html?sysversionId=' + sysversionId;   // 新改跳转页面
        },
        //编辑
        gotoPage(val){
            $('#my-alert').modal({
                relatedTarget: this,
            });
            this.flag = false;
                this.editObj.versionNo = val.versionNo;
                this.editObj.versionUpdateTime = this.getTimer();
                this.editObj.versionUrl = val.versionUrl;
                this.editObj.sysversionId = val.sysversionId;
            
        },
        confirmBtn(){
             //创建 formData 对象并添加数据
             let formData = new FormData();
            if(this.flag === true){
                formData.set("id",this.versionObj.id);
                formData.set("versionNo",this.editObj.versionNo);
                formData.set("versionUpdateTime",this.getTimer());
                formData.set("uploadFile",this.editObj.versionCopyUrl);
                axios({
                    method: "post",
                    url: App.envUrl.backtrackUrl+"version/saveSysMaintainVersion",
                    // url: 'http://192.168.1.61:8080/slxt-web/version/saveSysMaintainVersion',
                    data: formData,
                    headers:{"Content-Type":"multipart/form-data"},
                })
                .then((data) => {
                    console.log(data,'新增');
                    this.getData();
                })
                .catch((err) => {});
            }else{
                formData.set("id",this.versionObj.id);
                formData.set("sysversionId",this.editObj.sysversionId);
                formData.set("versionNo",this.editObj.versionNo);
                formData.set("versionUpdateTime",this.getTimer());
                formData.set("uploadFile",this.editObj.versionCopyUrl);
                axios({
                    method: "post",
                    url: App.envUrl.backtrackUrl+"version/updateSysMaintain",
                    // url: 'http://192.168.1.61:8080/slxt-web/version/updateSysMaintain',
                    data: formData,
                })
                .then((data) => {
                    console.log(data,'更新');
                    this.getData();
                })
                .catch((err) => {});
            }
        },
        getTimer() {
            var date = new Date();
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            var w = date.getDay();
            var w1 = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
            var h = date.getHours();
            h = h < 10 ? '0' + h : h;
            var min = date.getMinutes();
            min = min < 10 ? '0' + min : min;
            var s = date.getSeconds();
            s = s < 10 ? '0' + s : s;
          
            return y + '-' + m + '-' + d + ' ' + h + ':' + min + ':' + s;
          },
        //上传文件
        fileChange(val){
            let tem = val.target.files[0];
             this.editObj.versionCopyUrl = tem;
        },
        //分页
        selectPage(page){
            this.nowPage = page;
            this.getData();
        },
        offsetPage(offset){
            this.nowPage = this.nowPage + offset;
            this.getData();
        },
        skipPage() {
        	this.nowPage = document.getElementById('page-num').value;
        	document.getElementById('page-num').value = '';
        	this.getData();
        },
    }
   
});
